﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Details
{
    //Nhân viên
    public partial class StaffUC : DetailUC
    {
        public StaffUC()
        {
            InitializeComponent();
            this.ObjectName = "nhân viên";
            this.Code = "Staff";
            this.Type = new Staff();
        }

        
       

        protected override long DetailDisplay()
        {
            Staff staff = new Staff();
            if(ID>0)
            {
                staff = (Staff)RegisterService.RegisterServices.StaffService.GetByID(ID);
            }
            txtcode.Text = staff.Code;
            txtname.Text = staff.Name;
            dateEdit_birthday.EditValue =ID<0?DateTime.Now:staff.BirthDay;
            txtaddress.Text = staff.Address1;
            txtaddress2.Text = staff.Address2;
            txtphone.Text = staff.Phone;
            txtindentifycard.Text = staff.IndentityCard;

            radioGroupSex.EditValue = staff.Sex;
            txtregency.Text = staff.Regency;
            dateEdit_ngayvaolam.DateTime = staff.StartDateWork;
            dateEdit_ngaykyhd.DateTime = staff.DateOfSignContract;
            txt_sosobhxh.Text = staff.SocialInsuranceNumber;
            txtnote.Text = staff.Note;

            return ID;
            
        }

        protected override long Save()
        {
            Staff staff = new Staff();
            if (ID > 0)
            {
                staff = (Staff)RegisterService.RegisterServices.StaffService.GetByID(ID);
            }
            else
            {
                staff.CreateDate = DateTime.Now;
            }
            staff.Code = txtcode.Text;
            staff.Name = txtname.Text;
            staff.BirthDay = (DateTime)dateEdit_birthday.EditValue;
            staff.Address1 = txtaddress.Text;
            staff.Address2 = txtaddress2.Text;
            staff.Phone = txtphone.Text;
            staff.ModifiedDate = DateTime.Now;
            staff.IndentityCard = txtindentifycard.Text;
            staff.Note = txtnote.Text;
            staff.Regency = txtregency.Text;
            staff.Sex = radioGroupSex.EditValue.ToString();
            staff.SocialInsuranceNumber = txt_sosobhxh.Text;
            staff.StartDateWork = dateEdit_ngayvaolam.DateTime;
            staff.DateOfSignContract = dateEdit_ngayvaolam.DateTime;
           

            ID = RegisterService.RegisterServices.StaffService.Save(staff, ref ErrorMess);
           
            return ID;
        }


        public override bool Delete(long SelectedID)
        {
            return RegisterService.RegisterServices.StaffService.Delete((Staff)RegisterService.RegisterServices.StaffService.GetByID(SelectedID));

        }

     
     

        private void StaffUC_Load(object sender, EventArgs e)
        {
           // AddTextChanged(this.groupControl1.Controls);
            AddTextChanged(this.xtraScrollableControl1.Controls);
        }


    }
}
